//
//  UserManager.m
//  test
//
//  Created by 朱圳 on 2018/1/13.
//  Copyright © 2018年 朱圳. All rights reserved.
//
#define User @"User"
#import "UserManager.h"

@implementation UserManager 

//保存
+(void)save:(UserModel *)user{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    /****************学生***************************/
     [userDefaults removeObjectForKey:@"classification"];//先移除
     [userDefaults setObject:@"student" forKey:@"classification"];//再添加
     [userDefaults setObject:user.sid forKey:@"sid"];
     [userDefaults setObject:user.password forKey:@"spassword"];
    
     [userDefaults setObject:user.name forKey:@"name"];
     [userDefaults setObject:user.sImg forKey:@"sImg"];
     [userDefaults setObject:user.sex forKey:@"sex"];
     [userDefaults setObject:user.phone forKey:@"phone"];
     [userDefaults setObject:user.college forKey:@"college"];
     [userDefaults setObject:user.jieshu forKey:@"jieshu"];
     [userDefaults setObject:user.goal forKey:@"goal"];
     [userDefaults setObject:user.Applytime forKey:@"Applytime"];
     [userDefaults setObject:user.QQ forKey:@"QQ"];
     [userDefaults setObject:user.Winxin forKey:@"Winxin"];
     [userDefaults setObject:user.BirthDay forKey:@"BirthDay"];
     [userDefaults setObject:user.dadphone forKey:@"dadphone"];
     [userDefaults setObject:user.mumphone forKey:@"mumphone"];
     [userDefaults setObject:user.BuyCourse forKey:@"BuyCourse"];
     [userDefaults setObject:user.Baiduyun forKey:@"Baiduyun"];
     [userDefaults setObject:user.Vyan forKey:@"Vyan"];
     [userDefaults setObject:user.Classes forKey:@"Classes"];
    [userDefaults setObject:user.address forKey:@"address"];
     [userDefaults setObject:user.english forKey:@"english"];
     [userDefaults setObject:user.math forKey:@"math"];
     [userDefaults setObject:user.mailbook forKey:@"mailbook"];
    
    
    /****************教务老师***************************/
    [userDefaults setObject:user.jname forKey:@"jname"];
    [userDefaults setObject:user.jphone forKey:@"jphone"];
    [userDefaults setObject:user.jqq forKey:@"jqq"];
    [userDefaults setObject:user.jwechat forKey:@"jwechat"];
    [userDefaults setObject:user.jid forKey:@"jid"];
    [userDefaults setObject:user.jpic forKey:@"jpic"];
    /****************专业老师***************************/
    [userDefaults setObject:user.pname forKey:@"pname"];
    [userDefaults setObject:user.pphone forKey:@"pphone"];
    [userDefaults setObject:user.pqq forKey:@"pqq"];
    [userDefaults setObject:user.pwechat forKey:@"pwechat"];
    [userDefaults setObject:user.ppic forKey:@"ppic"];
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:user];
    [userDefaults setObject:data forKey:User];
    [userDefaults synchronize];
    
}

+(UserModel *)me{
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    NSData *data = [userDefaults objectForKey:User];
    UserModel *user = nil;
    if (data) {
        user = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    }
    return user;
}

+(void)loginOut{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    [userDefaults removeObjectForKey:User];
    [userDefaults removeObjectForKey:@"name"];
    [userDefaults removeObjectForKey:@"classification"];
}

+(BOOL)isLogining{
    
    NSUserDefaults *userDefaults =[NSUserDefaults standardUserDefaults];
    NSString *userName = [userDefaults objectForKey:@"name"];
    NSString *classification = [userDefaults objectForKey:@"classification"];

    if (userName && classification) {
        return YES;
    }else{
        return NO;
    }
}
@end
